package enumtest;

public enum Operator {
	ADD ("+") {//跟构造传参数保持一致
        @Override
        public int calculate(int a, int b) {
        	System.out.println("this getOperator is:"+this.getOperator());
            return a + b;
        }
    },
    SUBTRACT ("-") {
        @Override
        public int calculate(int a, int b) {
        	System.out.println("this getOperator is:"+this.getOperator());
            return a - b;
        }
    },
    MULTIPLY  ("*") {
        @Override
        public int calculate(int a, int b) {
        	System.out.println("this getOperator is:"+this.getOperator());
            return a * b;
        }
    },
    DIVIDE ("/") {
        @Override
        public int calculate(int a, int b) {
            if (b == 0) {
                throw new IllegalArgumentException("divisor must not be 0");
            }
            System.out.println("this getOperator is:"+this.getOperator());
            return a / b;
        }
    };
    Operator (String operator) {//有参构造
        this.operator = operator;
    }  
    private String operator;
    public abstract int calculate(int a, int b);
    public String getOperator() {
        return operator;
    }
}
